﻿using B.S.Orders.ErrorCord;
using B.S.Orders.Write.Api.Application.Command.OrdersCommands;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Orders.Write.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrdersController : ControllerBase
    {
        private readonly IMediator mediator;

        public OrdersController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 添加订单管理
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CreateOrders(CreateOrdersCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 删除订单管理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> DelOrders(DelOrdersCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 修改订单管理数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> UpdOrders(UpdOrdersCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> DeletedOrders(DeletedOrdersCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
    }
}
